package com.fengye.kafka.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;

@Service
public class KafkaConsumer {

    private static final Logger logger = LoggerFactory.getLogger(KafkaConsumer.class);

    //
    // @KafkaListener(
    //         topicPattern = "test-.*,my-topic-.*,i18n-#{environment.getProperty('spring.application.name')},i18n-#{environment.getProperty('spring.application.name')}-.*",
    //         groupId = "#{T(cn.hutool.core.util.IdUtil).getSnowflake().nextIdStr()}")
    // public void consume(String message) {
    //     System.out.println("Received message: " + message);
    // }

    @KafkaListener(
            topics = "i18n-#{environment.getProperty('spring.application.name')}",
            groupId = "#{T(cn.hutool.core.util.IdUtil).getSnowflake().nextIdStr()}")
    public void consume4(String message) {
        System.out.println("[topics i18n-test] Received message: " + message);
    }

    @KafkaListener(
            topicPattern = "i18n-#{environment.getProperty('spring.application.name')}-.*",
            groupId = "#{T(cn.hutool.core.util.IdUtil).getSnowflake().nextIdStr()}")
    public void consume2(String message) {
        // logger
        System.out.println("[通配符 i18n.*] Received message: " + message);
    }


    @KafkaListener(
            topicPattern = "sdsp.*",
            groupId = "#{T(cn.hutool.core.util.IdUtil).getSnowflake().nextIdStr()}")
    public void consume5(String message) {
        System.out.println("[通配符 sdsp.*] Received message: " + message);
    }

}
